// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init()
const db = cloud.database()
const _ = db.command

// 云函数入口函数
exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext()

  let organize_member = await db.collection('kq_organize').where({
    '_id':event._id
  }).get();
  record = organize_member.data[0].member
  for(var i = 0;i < record.length;i++){
      record[i].rid = Math.round(Math.random()*1000000000 + 9999999999)
  }

  return db.collection('kq_record').add({
    data:{
      _openid: wxContext.OPENID,
      title: event.title,
      passwd: event.passwd,
      check_status: event.check_status,
      record_member: record
    }
  })

  // return {
  //   event,
  //   openid: wxContext.OPENID,
  //   appid: wxContext.APPID,
  //   unionid: wxContext.UNIONID,
  // }
}